import request from "@/utils/request";
import type {
  LoginData,
  LoginResult,
  UpdateSkinData,
  UserInfoVo,
} from "./types";
import type { AxiosPromise } from "axios";

/**
 *  用户登录
 */
export function login(data: LoginData): AxiosPromise<LoginResult> {
  const params = {
    ...data,
    clientId: data.clientId || import.meta.env.VITE_APP_CLIENT_ID,
    grantType: "password",
    userType: "pc_web",
  };
  return request({
    url: "/auth/login",
    headers: {
      isToken: false,
      isEncrypt: true,
      repeatSubmit: false,
    },
    method: "post",
    data: params,
  });
}

/**
 *  获取用户详细信息
 */
export function getInfo(): AxiosPromise<any> {
  return request({
    url: "/business/userInfo/getInfo",
    method: "get",
  });
}

/**
 *  修改用户信息
 */
export function updUserInfo(
  updUserInfo: UserInfoVo | UpdateSkinData
): AxiosPromise<any> {
  return request({
    url: "/business/userInfo",
    method: "put",
    data: updUserInfo,
  });
}

/**
 *  获取用户卡片信息
 */
export function getCardUInfo(id: string): AxiosPromise<any> {
  return request({
    url: `/business/userInfo/getCardUInfo/${id}`,
    method: "get",
  });
}

/**
 *  获取用户附加扩展信息
 */
export function getUserInfoExt(id: string): AxiosPromise<any> {
  return request({
    url: `/business/userInfo/getUserInfoExt/${id}`,
    method: "get",
  });
}

/**
 * 注销
 */
export function logout() {
  return request({
    url: "/auth/logout",
    method: "post",
  });
}
